package service

import (
	"fly/models"
	"github.com/beego/beego/v2/client/orm"
)

type SysMenuService struct {
	BaseService
}

// GetUserMenuList 根据userId查询
func (c *SysMenuService) GetUserMenuList(userId int64, menuType *int) (list []*models.SysMenu, err error) {
	o := orm.NewOrm()
	qb, _ := orm.NewQueryBuilder("mysql")
	qb.Select("sys_menu.*").From("sys_role_user").LeftJoin(
		"sys_role_menu").On("sys_role_user.role_id = sys_role_menu.role_id").LeftJoin(
		"sys_menu").On("sys_role_menu.menu_id = sys_menu.id").Where(
		"sys_role_user.user_id=? AND sys_menu.menu_type=?").OrderBy("sys_menu.sort").Asc()
	sql := qb.String()
	_, err = o.Raw(sql, userId, menuType).QueryRows(&list)
	return
}
